package scau.erps.view.base;

import java.awt.Dimension;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;

import scau.erps.app.Erps;
import scau.erps.entity.Team;
import scau.erps.service.LoanService;
import scau.erps.service.impl.LoanServiceImpl;

/**
 * 财务信息面板
 * @author DCJ
 *
 */
public class FinancePanel extends JPanel{
	private static final long serialVersionUID = 1L;
	private JLabel cash,longLoan,shortLoan,highLoan,receivableAccount,payableAccount;
	public FinancePanel(){		
		JPanel	financePanel = new JPanel();				
		financePanel.setPreferredSize(new Dimension(150,200));
		financePanel.setLayout(new GridLayout(6,2));
		financePanel.setBorder(BorderFactory.createTitledBorder("财务信息"));
		JLabel cashLabel = new JLabel("当前现金:");
		JLabel longLoanLabel = new JLabel("长期贷款:");
		JLabel shortLoanLabel  = new JLabel("短期贷款:");
		JLabel highLoanLabel  = new JLabel("高利贷:");
		JLabel receivableAccountLabel = new JLabel("应收账款:");
		JLabel payableAccountLabel = new JLabel("应付账款:");
		cash = new JLabel("0");
		longLoan = new JLabel("0");
		shortLoan  = new JLabel("0");
		highLoan  = new JLabel("0");
		receivableAccount = new JLabel("0");
		payableAccount= new JLabel("0");
		financePanel.add(cashLabel);
		financePanel.add(cash);
		financePanel.add(longLoanLabel);
		financePanel.add(longLoan);
		financePanel.add(shortLoanLabel);
		financePanel.add(shortLoan);
		financePanel.add(highLoanLabel);
		financePanel.add(highLoan);
		financePanel.add(receivableAccountLabel);
		financePanel.add(receivableAccount);
		financePanel.add(payableAccountLabel);
		financePanel.add(payableAccount);
		this.add(financePanel);
	}
	
	/**
	 * 设置财务数据
	 */
	public void setFinanceData(){
		Team team = Erps.getCurrentTeam();
		LoanService loanService = Erps.getIocInstance().get(LoanServiceImpl.class);
		cash.setText(""+Erps.getSand().getCash());
		longLoan.setText(""+loanService.getLoanAmount(team.getId(), "长贷"));
		shortLoan.setText(""+loanService.getLoanAmount(team.getId(), "短贷"));
		highLoan.setText(""+loanService.getLoanAmount(team.getId(), "高利贷"));
	}
}
